using System.Collections.Generic;
using System.Linq;

using Cooking.Client.CaliburnExtensions;
using Cooking.Client.Querying;
using Cooking.Client.Services;

namespace Cooking.Client.ViewModels.Coroutines
{
    public class FindRecipesCoroutine : SimpleCoroutine
    {
        public IQueryAgent QueryAgent { get; set; }

        public string PartialTitle { get; set; }

        public string PartialDescription { get; set; }

        public int MinimumRating { get; set; }

        public IEnumerable<Recipe> Recipes { get; internal set; }

        protected override void OnExecute()
        {
            QueryAgent.FindRecipes(MinimumRating, PartialTitle, PartialDescription,
                recipes =>
                {
                    Recipes = recipes.ToArray();
                    OnComplete();
                });
        }
    }
}